package com.three.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.three.dao.ClazzDao;
import com.three.dao.SRrecordDao;
import com.three.dao.UserDao;
import com.three.entity.SRrecord;
import com.three.entity.User;
import com.three.service.SRrecordService;

@Service
public class SRrecordServiceImpl implements SRrecordService {

	@Autowired
	SRrecordDao sRrecordDao;
	@Autowired
	ClazzDao clazzDao;
	@Autowired
	UserDao userDao;

	@Override
	public List<SRrecord> findSRrecords(Integer uid, Integer cid) {
		List<Integer> ucids = clazzDao.findUcidByUidWithCid(uid, cid);
		return sRrecordDao.findSRrecords(ucids.get(0));
	}

	@Override
	public List<User> findStudentsWithSRrecord(Integer cid) {
		List<User> users = userDao.findStudentsByCid(cid);
		for(int i = 0;i<users.size();i++){
			List<Integer> ucids = clazzDao.findUcidByUidWithCid(
					users.get(i).getId(), cid);
			List<SRrecord> sRrecords = sRrecordDao.findSRrecords(ucids.get(0));
			users.get(i).setsRrecord(sRrecords.get(0));
		}
		return users;
	}

}
